
const btn = document.querySelector('#btn-login')

btn.addEventListener('click', async function () {
  const username = document.querySelector('[name="username"]').value.trim()
  const password = document.querySelector('[name="password"]').value.trim()

  if (!username || !password) {
    document.querySelector('#myToast .toast-body').innerHTML = "用户名密码不能为空"

    myToast.show()
  }

  const result = await axios({
    url: "/login",
    method: "post",
    data: {
      username,
      password
    }
  })
  // console.log(result)

  if (result.status === 200) {
    document.querySelector('#myToast .toast-body').innerHTML = result.data.message

    myToast.show()

    localStorage.setItem('token2', result.data.data.token)

    setTimeout(() => {
      location.href = './index.html'
    }, 1500)
  }
})

